home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / documents / X / xdocsSrc / pidinfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-11  |  745 b   |  30 lines

  1. /* cc -o pidinfo pidinfo.c */
  2.  
  3. #include <stdio.h>
  4. #include <errno.h>
  5. #include <fcntl.h>
  6. #include <sys/procfs.h>
  7.  
  8. main(int argc, char **argv)
  9. {
  10.    char buf[32];
  11.    int fd, tries;
  12.    prstatus_t status;
  13.  
  14.    sprintf(buf, "/proc/%d", atoi(argv[1]));
  15.    if ((fd=open(buf, O_RDWR)) == -1) exit(1);
  16.    for(;;) {
  17.        tries = 0;
  18.        while ((tries < 5) && (ioctl(fd, PIOCSTATUS, &status) == -1) &&
  19.           (errno == EAGAIN))
  20.            tries++;
  21.        if (tries == 5) exit(2);
  22.        printf(">> snap of sys and usr for %s\n", buf);
  23.        printf("   usr = %5d.%03d\n",
  24.        status.pr_utime.tv_sec, status.pr_utime.tv_nsec/1000000);
  25.        printf("   sys = %5d.%03d\n",
  26.        status.pr_stime.tv_sec, status.pr_stime.tv_nsec/1000000);
  27.        sleep(1);
  28.    }
  29. }
  30.